import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import undetected_chromedriver as uc

def get_proxy():
    url = "https://dps.kdlapi.com/api/getdps/?secret_id=ondbxg8msovv7ury9qbe&signature=zft63syjut8u3og5m9j5wung50mwah5f&num=1&format=text&sep=1"
    proxy_address = requests.get(url)
    return proxy_address.text


# 快代理的认证信息
proxy_username = "d2231274096"
proxy_password = "ela9v3e9"


# 构造带认证信息的代理URL
proxy_address = get_proxy()
print(f"===============使用代理:{proxy_address}")
proxy_host = proxy_address.split(":")[0]            # proxy ip
proxy_port = proxy_address.split(":")[1]            # proxy port

proxy_url = f"http://{proxy_username}:{proxy_password}@{proxy_host}:{proxy_port}"

options = webdriver.ChromeOptions()
options.add_argument(f'--proxy-server={proxy_url}') # 注意这里没有 `http://` 前缀了
browser = uc.Chrome(options=options)

browser.set_window_size(1366,768)
# 验证代理是否生效
browser.get('https://www.ip112.com/')
time.sleep(20)

